package wzc.design_pattern.behaviour.state;

/**
 * @Author 那和不是个啥
 * @Date 2025/7/20
 * @Description
 */

public class HasCoinState implements VendingMachineState {
    private VendingMachine vendingMachine;

    public HasCoinState(VendingMachine vendingMachine) {
        this.vendingMachine = vendingMachine;
    }

    @Override
    public void insertCoin() {
        System.out.println("已经投币，请选择商品。");
    }

    @Override
    public void ejectCoin() {
        System.out.println("退币成功。");
        // 转换到没有投币状态
        vendingMachine.setCurrentState(new NoCoinState(vendingMachine));
    }

    @Override
    public void pressButton() {
        System.out.println("商品正在出货，请稍等...");
        // 转换到售货状态
        vendingMachine.setCurrentState(new SoldState(vendingMachine));
    }

    @Override
    public void dispense() {
        System.out.println("请按下按钮选择商品。");
    }
}
